package com.timesheet.server.core.mapper;

import java.lang.reflect.Field;

public class Mapper<To> {
	
	
	
	

	public To map(To a1, Object from) {

		Class<? extends Object> a = a1.getClass();

		Class<? extends Object> b = from.getClass();

		Field[] declaredFields = a.getDeclaredFields();
		Field[] declaredFields2 = b.getDeclaredFields();

		for (int i = 0; i < declaredFields2.length; i++) {

			Field field1 = declaredFields[i];
			field1.setAccessible(true);

			Field field2 = declaredFields2[i];
			field2.setAccessible(true);

			for (Field field : declaredFields) {

				if (field.getName().equals(field2.getName()) && !field.getName().equals("serialVersionUID")) {

					Object object;
					try {
						object = field2.get(from);
						field1.set(a1, object);
					}
					catch (Exception exception) {
						exception.printStackTrace();
					}

				}
			}
		}

		return a1;

	}
	
	public static void main(String[] args) {
		
	}

}